﻿using System;
using System.Windows.Forms;

namespace HostingSample
{
	public class MessageService : IMessageService
	{
		public MainWindow Window {
			get;
			set;
		}

		public string Caption {
			get {
				if (Window == null) {
					return "Main Application";
				}
				return Window.CaptionText;
			}
		}

		public bool ShowQuestion(string message) {
			return ShowQuestion(message, Caption);
		}

		public bool ShowQuestion(string message, string caption) {
			var result = MessageBox.Show(Window, message, caption ?? Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
			return result == DialogResult.Yes;
		}

		public void ShowMessage(string message) {
			ShowMessage(message, Caption);
		}

		public void ShowMessage(string message, string caption) {
			MessageBox.Show(Window, message, caption ?? Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
		}

		public void ShowWarning(string message) {
			ShowWarning(message, Caption);
		}

		public void ShowWarning(string message, string caption) {
			MessageBox.Show(Window, message, caption ?? Caption, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
		}

		public void ShowError(string message) {
			ShowError(message, Caption);
		}

		public void ShowError(string message, string caption) {
			MessageBox.Show(Window, message, caption ?? Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
		}
	}
}
